package com.samuel.profile;


import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @date:2017/11/22
 * @time: 11:11
 * @author:zhaoyang
 * @desc:
 **/
public class ProfileMain {

    public static void main(String[] args) {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        String[] profiles = context.getEnvironment().getActiveProfiles();
        String temp ="";
        if(profiles!=null){
            for(int i=0;i<profiles.length;i++){
                temp = temp + profiles[i]==null?"":(String)profiles[i] + ",";
            }
        }
        System.out.println(" 【"+temp+"】");
        context.getEnvironment().setActiveProfiles("prod");


        /**
         *  后置注册Bean的配置类，不然Bean未定义，抛异常
         */
        context.register(ProfileConfig.class);
        //刷新容器
        context.refresh();

        Demobean demobean = context.getBean(Demobean.class);
        System.out.println(demobean.getContent());

         context.close();

    }
}
